﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EHSubmit.Util;
using EHSubmit.Model;
using EHSubmit.Logic;


namespace EHSubmit.Logic.Services 
{
    /// <summary>
    ///ServicesProvider 的摘要说明
    /// </summary>
    public class ServicesProvider
    {
        public ServicesProvider()
        {

        }

        /// <summary>
        /// 提供相应天气信息
        /// </summary>
        /// <returns>添加数据进入Session中</returns>
        public string[] WeatherService()
        {
            try
            {
                //EHSubmit.IPService.IpAddressSearchWebService IPService = new EHSubmit.IPService.IpAddressSearchWebService();  //用于获取城市信息
                ////String UserIP = getIP();
                //String UserIP = "113.57.91.123";      //测试用
                //String[] IPInfo = IPService.getCountryCityByIp(UserIP);
                //String[] IPInfoValid = IPInfo[1].Split(' ');
                //String[] Temp = IPInfoValid[0].Split('省');
                //String[] Temp2 = Temp[1].Split('市');
                //String CityName = Temp2[0];

                //EHSubmit.WeatherService.WeatherWebService WeatherService = new EHSubmit.WeatherService.WeatherWebService();   //用于获取天气信息
                //String[] WeatherInfo = WeatherService.getWeatherbyCityName(CityName);
                ////Context.Session["Temperature"] = WeatherInfo[5];                                            //天气气温范围                                         //天气气温范围
                ////Context.Session["Weather"] = WeatherInfo[6];                                                //天气概况
                ////Context.Session["Wind"] = WeatherInfo[7];                                                   //风向
                ////Context.Session["WeatherPhoto"] = "images/weather/a_" + WeatherInfo[8];                    //图片路径
                String[] Weather = new String[4];
                //Weather[0] = WeatherInfo[5];
                //Weather[1] = WeatherInfo[6];
                //Weather[2] = WeatherInfo[7];
                //Weather[3] = "images/weather/a_" + WeatherInfo[8];
                //return Weather;
                Weather[0] = "26℃-29℃";
                Weather[1] = "7月22日 晴";
                Weather[2] = "无持续风向微风";
                Weather[3] = "images/weather/a_0.gif";
                return Weather;
            }
            //catch (System.Net.WebException we) {
            //    string[] error = new String[1];
            //    error[0] = Constants.INFO_NETWORK_ERR;
            //    LogHelper.Log(we.Message, we);
            //    return error;
            //}
            catch
            {
                string[] error = new String[1];
                error[0] = "这城市或区域暂时不被支持";
                return error;
            }
            

        }


        /// <summary>
        /// 获取客户端IP
        /// </summary>
        /// <returns>返回String类型的IP字符串</returns>
        public string getIP()
        {
            if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                return System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];
            else
                return System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            //return "202.114.88.145";
        }
    }

}

